'use strict';
exports.main = async (event, context) => {
	const SECRET = '4c9b446f9dc58fc009b2a5e13b985032'
	const APPID = 'wxf9a6e81004d5a574'
	const code2SessionApi = `https://api.weixin.qq.com/sns/jscode2session?appid=${APPID}&secret=${SECRET}&js_code=${event.js_code}&grant_type=authorization_code`
	let res = await uniCloud.httpclient.request(code2SessionApi, 
	{
		method: 'GET',
	})
	//返回数据给客户端
	var resData = JSON.parse(res.data.toString())
	if ('openid' in resData) {
		return resData.openid
	} else {
		return resData.errcode
	}
};
